Navigation

Use Exceptions Rather Than Return Codes

Don’t force caller to do validation

Write Your Try-Catch-Finally Statement First

Use Unchecked Exceptions

checked exception: documenting in your code what exceptions can be thrown - violates open/close, creates too much clutter

Provide Context with Exceptions

Define Exception Classes in Terms of a Caller’s Needs

wrap third party code to reduce dependency

if an api is providing more functionality/exceptions than you need, wrap it

Define the Normal Flow

Don’t execute normal code in catch statements; avoid/surpress exceptions by having the invoked method return a valid Special Case object providing the expected result

Don’t Return Null

Throw an exception or return a Special Case object if possible

Don’t Pass Null

assertions / argument validation passes on the problem; nulls proliferate